import style from "./index.css";
import { connect } from "dva";
import Link from "umi/link";
import { Button,Form, Icon, Input,message } from "antd";
import {useState,useEffect} from 'react';

function Index(props) {
	const FormItem = Form.Item;	
	let value1 ="";
	let value2 ="";
	const [count,setCount]=useState(0)
	useEffect(()=>{
		console.log(props.str)
		if(props.str=='success'&&count!= 0){
			message.success('登录成功~')
			localStorage.setItem('token',props.token)
			localStorage.setItem('userName',value1.props.defaultValue)
			props.history.push("/home/userList")
		}
	},[count])
  return (
    <div className={style.container}>
    
      <Form className='form-container'>
    
        <FormItem>
            <Input type="text"
              className='form-input' 
              prefix={<Icon type="user" />}
              defaultValue="admin001"
			  ref={(val) =>value1 = val}
            />
		</FormItem>
		<FormItem>
            <Input.Password
              className='form-input'
              prefix={<Icon type="lock" />}
              defaultValue="admin@12138"
			  ref={(val) =>value2 = val}
            />
        </FormItem>
		{/*<Link to="/home/userList"></Link>*/}	 
		<Button type="primary" className='form-button' 
			onClick={()=>props.dispatch({
				type:'info/getData',
				payload:{
					userName:value1.props.defaultValue,
					password:value2.props.defaultValue
				}
			}).then(()=>{
				setCount(count+1)
			})
			}>登录</Button>
      </Form>
    </div>
  );
}

export default connect(state=>state.info)(Index);
